/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package aigle.bvieillard.gmf.tp2.provider;

import aigle.bvieillard.gmf.tp2.util.tp2AdapterFactory;

import java.util.ArrayList;
import java.util.Collection;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;

import org.eclipse.emf.edit.provider.ChangeNotifier;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.IChangeNotifier;
import org.eclipse.emf.edit.provider.IDisposable;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertySource;
import org.eclipse.emf.edit.provider.INotifyChangedListener;
import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
import org.eclipse.emf.edit.provider.ITreeItemContentProvider;

/**
 * This is the factory that is used to provide the interfaces needed to support Viewers.
 * The adapters generated by this factory convert EMF adapter notifications into calls to {@link #fireNotifyChanged fireNotifyChanged}.
 * The adapters also support Eclipse property sheets.
 * Note that most of the adapters are shared among multiple instances.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public class tp2ItemProviderAdapterFactory extends tp2AdapterFactory implements ComposeableAdapterFactory, IChangeNotifier, IDisposable {
	/**
	 * This keeps track of the root adapter factory that delegates to this adapter factory.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ComposedAdapterFactory parentAdapterFactory;

	/**
	 * This is used to implement {@link org.eclipse.emf.edit.provider.IChangeNotifier}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected IChangeNotifier changeNotifier = new ChangeNotifier();

	/**
	 * This keeps track of all the supported types checked by {@link #isFactoryForType isFactoryForType}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected Collection<Object> supportedTypes = new ArrayList<Object>();

	/**
	 * This constructs an instance.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public tp2ItemProviderAdapterFactory() {
		supportedTypes.add(IEditingDomainItemProvider.class);
		supportedTypes.add(IStructuredItemContentProvider.class);
		supportedTypes.add(ITreeItemContentProvider.class);
		supportedTypes.add(IItemLabelProvider.class);
		supportedTypes.add(IItemPropertySource.class);
	}

	/**
	 * This keeps track of the one adapter used for all {@link aigle.bvieillard.gmf.tp2.LivreRecettes} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected LivreRecettesItemProvider livreRecettesItemProvider;

	/**
	 * This creates an adapter for a {@link aigle.bvieillard.gmf.tp2.LivreRecettes}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createLivreRecettesAdapter() {
		if (livreRecettesItemProvider == null) {
			livreRecettesItemProvider = new LivreRecettesItemProvider(this);
		}

		return livreRecettesItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link aigle.bvieillard.gmf.tp2.Recette} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected RecetteItemProvider recetteItemProvider;

	/**
	 * This creates an adapter for a {@link aigle.bvieillard.gmf.tp2.Recette}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createRecetteAdapter() {
		if (recetteItemProvider == null) {
			recetteItemProvider = new RecetteItemProvider(this);
		}

		return recetteItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link aigle.bvieillard.gmf.tp2.Ingredient} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected IngredientItemProvider ingredientItemProvider;

	/**
	 * This creates an adapter for a {@link aigle.bvieillard.gmf.tp2.Ingredient}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createIngredientAdapter() {
		if (ingredientItemProvider == null) {
			ingredientItemProvider = new IngredientItemProvider(this);
		}

		return ingredientItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link aigle.bvieillard.gmf.tp2.Vin} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected VinItemProvider vinItemProvider;

	/**
	 * This creates an adapter for a {@link aigle.bvieillard.gmf.tp2.Vin}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createVinAdapter() {
		if (vinItemProvider == null) {
			vinItemProvider = new VinItemProvider(this);
		}

		return vinItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link aigle.bvieillard.gmf.tp2.Compose} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ComposeItemProvider composeItemProvider;

	/**
	 * This creates an adapter for a {@link aigle.bvieillard.gmf.tp2.Compose}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createComposeAdapter() {
		if (composeItemProvider == null) {
			composeItemProvider = new ComposeItemProvider(this);
		}

		return composeItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link aigle.bvieillard.gmf.tp2.Localisation} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected LocalisationItemProvider localisationItemProvider;

	/**
	 * This creates an adapter for a {@link aigle.bvieillard.gmf.tp2.Localisation}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createLocalisationAdapter() {
		if (localisationItemProvider == null) {
			localisationItemProvider = new LocalisationItemProvider(this);
		}

		return localisationItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link aigle.bvieillard.gmf.tp2.Bouteille} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected BouteilleItemProvider bouteilleItemProvider;

	/**
	 * This creates an adapter for a {@link aigle.bvieillard.gmf.tp2.Bouteille}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createBouteilleAdapter() {
		if (bouteilleItemProvider == null) {
			bouteilleItemProvider = new BouteilleItemProvider(this);
		}

		return bouteilleItemProvider;
	}

	/**
	 * This returns the root adapter factory that contains this factory.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ComposeableAdapterFactory getRootAdapterFactory() {
		return parentAdapterFactory == null ? this : parentAdapterFactory.getRootAdapterFactory();
	}

	/**
	 * This sets the composed adapter factory that contains this factory.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setParentAdapterFactory(ComposedAdapterFactory parentAdapterFactory) {
		this.parentAdapterFactory = parentAdapterFactory;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean isFactoryForType(Object type) {
		return supportedTypes.contains(type) || super.isFactoryForType(type);
	}

	/**
	 * This implementation substitutes the factory itself as the key for the adapter.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter adapt(Notifier notifier, Object type) {
		return super.adapt(notifier, this);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object adapt(Object object, Object type) {
		if (isFactoryForType(type)) {
			Object adapter = super.adapt(object, type);
			if (!(type instanceof Class<?>) || (((Class<?>)type).isInstance(adapter))) {
				return adapter;
			}
		}

		return null;
	}

	/**
	 * This adds a listener.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void addListener(INotifyChangedListener notifyChangedListener) {
		changeNotifier.addListener(notifyChangedListener);
	}

	/**
	 * This removes a listener.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void removeListener(INotifyChangedListener notifyChangedListener) {
		changeNotifier.removeListener(notifyChangedListener);
	}

	/**
	 * This delegates to {@link #changeNotifier} and to {@link #parentAdapterFactory}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void fireNotifyChanged(Notification notification) {
		changeNotifier.fireNotifyChanged(notification);

		if (parentAdapterFactory != null) {
			parentAdapterFactory.fireNotifyChanged(notification);
		}
	}

	/**
	 * This disposes all of the item providers created by this factory. 
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void dispose() {
		if (livreRecettesItemProvider != null) livreRecettesItemProvider.dispose();
		if (recetteItemProvider != null) recetteItemProvider.dispose();
		if (ingredientItemProvider != null) ingredientItemProvider.dispose();
		if (vinItemProvider != null) vinItemProvider.dispose();
		if (composeItemProvider != null) composeItemProvider.dispose();
		if (localisationItemProvider != null) localisationItemProvider.dispose();
		if (bouteilleItemProvider != null) bouteilleItemProvider.dispose();
	}

}
